package com.yuanzong.wuliu.config.business;

import com.yuanzong.wuliu.common.utils.UtilsSupport;
import com.yuanzong.wuliu.common.utils.file.FileUtils;
import com.yuanzong.wuliu.common.utils.id.SnowFlakeUtils;
import com.yuanzong.wuliu.common.utils.spring.SpringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 项目运行时配置
 */
@Configuration
public class RunConfig {

    @Autowired
    private RunSupportLoader runSupportLoader;

    @Bean(name = "springUtils")
    public SpringUtils springUtils(ApplicationContext applicationContext) {
        SpringUtils springUtils = new SpringUtils();
        springUtils.setApplicationContext(applicationContext);
        return springUtils;
    }

    @Bean(name = "snowFlakeUtils")
    public SnowFlakeUtils snowFlakeUtils() {
        UtilsSupport utilsSupport = runSupportLoader.getInstance(UtilsSupport.class);
        SnowFlakeUtils snowFlakeUtils = new SnowFlakeUtils(utilsSupport);
        return snowFlakeUtils;
    }

    @Bean(name = "fileUtils")
    public FileUtils fileUtils() {
        UtilsSupport utilsSupport = runSupportLoader.getInstance(UtilsSupport.class);
        FileUtils fileUtils = new FileUtils(utilsSupport);
        return fileUtils;
    }
}
